package com.douyu.ocean.invoke;

import java.util.Random;

/**
 * @author leiruiqi on 2018/9/12
 */
public class PerformanceCore {

    public static Double getInvokeRateByName(String name){
        return PerformanceCollectUtil.getInvokeRate(name);
    }

    public static boolean needInvoke(double invokeRate){
        if(invokeRate>=1D){
            return true;
        }
        int num = new Random().nextInt(100);
        return invokeRate>1D*num/100;
    }

    public static boolean needInvoke(double historyInvokeRate,double boost){
        double rate =getRate(historyInvokeRate,boost);
        return needInvoke(rate);
    }

    public static double getRate(double historyInvokeRate,double boost){
        return historyInvokeRate*(1d+boost);
    }
}
